package com.wildish.core.interceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.wildish.core.controller.WebSupport;

public class RequestResponseBindInterceptor extends HandlerInterceptorAdapter {
	@Resource
	private WebSupport webSupport;
	/**
	 * 预处理
	 */
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		webSupport.getRequest().set(request);
		webSupport.getResponse().set(response);
		return true;
	}
	/**
	 * 执行完成后
	 */
	@Override
	public void afterCompletion(HttpServletRequest request,HttpServletResponse response,Object handler,Exception ex) {
		if (ex!=null) {
			StringBuilder sb = new StringBuilder();
			sb.append(request.getRemoteAddr()).append("\t");
			sb.append(request.getQueryString()).append("\n");
			// FIXME 输出异常日志
			System.out.println(sb.toString());
		}
	}
}
